package hot100;

import java.util.HashMap;
import java.util.List;

/**
 * @Author: wzp
 * @CreateTime: 2024-09-10  09:32
 * @Description: TODO
 * @Version: 1.0
 */
public class hot_17 {
    public List<String> letterCombinations(String digits) {
        HashMap<Character,char[]> map=new HashMap<>();
        map.put('2',new char[]{'a','b','c'});
        map.put('3',new char[]{'d','e','f'});
        map.put('4',new char[]{'g','h','i'});
        map.put('5',new char[]{'j','k','l'});
        map.put('6',new char[]{'m','n','o'});
        map.put('7',new char[]{'p','q','r','s'});
        map.put('8',new char[]{'t','u','v'});
        map.put('9',new char[]{'w','x','y','z'});
        int index=0;
        char[] chars = digits.toCharArray();
        List<String> res = new java.util.ArrayList<>();
        if(chars.length==0){
            return res;
        }
        dfs(index,chars,new StringBuilder(),res,map);
        return res;

    }
    private void dfs(int index,char[] chars,StringBuilder sb,List<String> res,HashMap<Character,char[]> map){
        if(index==chars.length){
            res.add(sb.toString());
            return;
        }
        char[] arr = map.get(chars[index]);
        for (int i = 0; i < arr.length; i++) {
            sb.append(arr[i]);
            dfs(index+1,chars,sb,res,map);
            sb.deleteCharAt(sb.length()-1);
        }
    }
}
